/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package batailledesardennes.game.map.imagemap;

import batailledesardennes.game.GameEnv;
import batailledesardennes.game.map.GameMap;
import batailledesardennes.game.map.imagemap.ImageBasedMapDrawer;
import batailledesardennes.util.geomFloat.Point;
import batailledesardennes.util.geomFloat.Polygon;
import batailledesardennes.util.geomFloat.path.Obstacle;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.SlickException;

/**
 *
 * @author charly
 */
public class ImageBasedGameMap extends GameMap {
   private ImageBasedMapDrawer drawer;

   public ImageBasedGameMap(int width, int height) {
      this.width = width;
      this.height = height;
      drawer = new ImageBasedMapDrawer();
   }

   @Override
   public void init(GameEnv env) {
      this.env = env;
      env.setMap(this);
      try {
         Image mapImage = new Image("batailledesardennes/assets/map/testmap-picture.png");
         drawer.setImage(mapImage);
//         Image obstacleImage = new Image("batailledesardennes/assets/map/testmap-accessmap3.bmp");
      } catch (SlickException ex) {
         Logger.getLogger(ImageBasedGameMap.class.getName()).log(Level.SEVERE, null, ex);
      }
      Polygon polygon = new Polygon(new Point(100f,300f), new Point(170f, 310f), new Point(160f, 287f), new Point(96f, 250f));
      Obstacle obs = new Obstacle(polygon);
      env.getMap().getAccessHandler().getNodeHandler().addObstacle(obs);
   }

   @Override
   public void draw(Graphics g) {
      drawer.draw(g);
      drawObstacles(g);
   }

   public void loadHeightMapFromImage(String imageName) throws SlickException {
      Image image = new Image("batailledesardennes/assets/map/" + imageName);
      byte[] textureData = image.getTexture().getTextureData();
      for (int i = 0; i < width; i++) {
         for (int j = 0; j < height; j++) {
            Color color = image.getColor(i, j);
            int blue = color.getBlue();
//            heightMap[i][j] = textureData[i + j * width];
         }
      }
   }
}
